<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'MyJsp.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<jsp:include page="/scripts/common/index.html"></jsp:include>
<jsp:include page="/scripts/dhtmlx/index.html"></jsp:include>
<jsp:include page="/scripts/jquery/index.html"></jsp:include>
<jsp:include page="/scripts/bootstrap/index.html"></jsp:include>
<link rel="stylesheet" href="${basepath }style/default.css">
</head>
<script type="text/javascript">
	var temp = false;
	function save() {
		var v = getDate();
		//alert(JSON.stringify(v));
		$.ajax({
			type : 'POST' ,
			url : 'page/system/user/UserGroup/doAddGroupRole' ,
			data : v,
			dataType : "json" ,
			async : true ,
			cache : false ,
			jsonpCallback : "null" ,
			success : function(response, status, statusText) {
				if (response.status) {
					if(response.content == "设置成功！") {//type != 1
						//SN.clearFormValue("MyForm");
						SN.alert.info("设置成功！", function() {
							query();
							closeWindow();
						});
					} else if (response.content == "设置失败！") {
						//SN.clearFormValue("MyForm");
						SN.alert.info("设置失败！", function() {
							query();
							closeWindow();
						});
					}
				} else {
					alert(response.content);
				}
			} ,
			error : function(response, status, statusText) {
				//alert(response + ":" + status + ":" + statusText);
			} ,
			complete : function(response, status, statusText) {
				//alert(response + ":" + status + ":" + statusText);
			}
		});
	}
	function query() {
		parent.query();
	}
	function closeWindow() {
		parent.w1.close();
	}
	/* checkbox点击事件 */
	function check(obj) {
		var ischecked = obj.getAttribute("isCheck");
		var backgroundimg = "${basePath}scripts/dhtmlx/codebase/imgs/dhxtree_terrace/";
		if (ischecked == "false") {
			obj.style.backgroundImage = "url('" + backgroundimg + "iconCheckAll.gif')";
			obj.setAttribute("isCheck", "true");
		} else if (ischecked == "true") {
			obj.style.backgroundImage = "url('" + backgroundimg + "iconUncheckAll.gif')";
			obj.setAttribute("isCheck", "false");
		}
	}
	function getDate(){
		var arr = ['userGroupCode','userGroupName'];
		var json = {};
		for(var i in arr){
			json[arr[i]] = $("#" + arr[i]).val();
		}
		var tabDate =getUserGroup();
		myDate = JSON.stringify(tabDate);
		json["tabDate"] = myDate;
		//alert(JSON.stringify(json));
		return json;
	}
	function getUserGroup(){
		var milasUrl={};//新建对象，用来存储所有数据
      	var subMilasUrlArr={};//存储每一行数据
      	var tableData={};
		$("#staffGroup div[isCheck='true']").each(function(i,n){
			 tableData[i]=new Array();
			$(this).parents(".checkDiv").find("input").each(function(tdindex,tditem){
		          tableData[i][tdindex]=$(tditem).val();//遍历每一个数据，并存入
		          subMilasUrlArr[i]=tableData[i];//将每一行的数据存入
		      });
		});
		 for(var key in subMilasUrlArr)
	     {
	         milasUrl[key]=subMilasUrlArr[key];//将每一行存入对象
	     }
		//alert(JSON.stringify(milasUrl));
	    return milasUrl;
	}
	//回到顶部按钮添加
	$(document).ready(function () {
            GP.goup({
                trigger: 100,
                bottomOffset: 30,
                locationOffset: 30,
                titleAsText: true,
               containerColor: '#7e7f7e'
            },"Panel_");
    });
		
</script>
<style>
.checkDiv {
	float: left;
	margin-left: 5px;
	margint-right: 5px;
	margin-top: 10px;
	width: 220px;
	height: 18px;
}

.checkDiv>div {
	float: left;
}

.checkDiv>label {
	float: left;
	margin-top: 3px;
	margin-left: 3px;
	font-weight: normal;
}
</style>
<body>
	<form class="form-horizontal MyForm" id="MyForm" name="MyForm" method="post" target="MyFrame" enctype="multipart/form-data">
		<table class="contTable">
			<tr class="firstTr">
				<td>
					<button onclick="save()" class="btn btn-primary" type="button">
						<span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>&nbsp;<span>保存</span>
					</button>
					<button onclick="closeWindow()" class="btn btn-primary" type="button">
						<span class="glyphicon glyphicon-remove-sign" aria-hidden="true"></span>&nbsp;<span>关闭</span>
					</button>
				</td>
			</tr>
			<tr height="25">
				<td>
					<%-- 用户账号：${map.userAccount} &nbsp;&nbsp;&nbsp;用户名称：${map.userName} --%>
					<div style="height: 25px;width: 98%;margin: auto;line-height: 25px;margin-top: 8px;">
						用户组编号：${map.userGroupCode} &nbsp;&nbsp;&nbsp;用户组名称：${map.userGroupName} <input type="hidden" value="${map.userGroupCode }" id="userGroupCode" /> <input type="hidden" value="${map.userGroupName }" id="userGroupName" />
					</div>
				</td>
			</tr>
			<tr style="height:auto">
				<td valign="top">
					<div id="Panel_" style="width:100%;height: 380px;overflow-y:auto;">
						<div class="blockBorder">
							<div class="titleS">
								<strong>设置用户组角色</strong>
							</div>
							<div class="tableCont" style="width: 90%;height:280px;overflow:auto;">
								<div class="popupCont" id="popupCont" style="display: block;">
									<table style="height:100%">
										<tr id="staffGroup">
											<td style="height:100%" valign="top"><c:forEach var="emp" items="${roleTeamList}">
													<div class="checkDiv">
														<div onclick="check(this)" isCheck="true" class="dhx_bg_img_fix" style="width:18px;height:18px;background-image: url('${basePath}scripts/dhtmlx/codebase/imgs/dhxtree_terrace/iconCheckAll.gif')"></div>
														<input type="hidden" value="${emp.roleCode }" /><label>${emp.roleName }</label>
													</div>
												</c:forEach> <c:forEach var="emp" items="${roleList}">
													<div class="checkDiv">
														<div onclick="check(this)" isCheck="false" class="dhx_bg_img_fix" style="width:18px;height:18px;background-image: url('${basePath}scripts/dhtmlx/codebase/imgs/dhxtree_terrace/iconUncheckAll.gif')"></div>
														<input type="hidden" value="${emp.roleCode }" /><label>${emp.roleName }</label>
													</div>
												</c:forEach></td>
										</tr>
									</table>
								</div>
							</div>
						</div>
					</div>
				</td>
			</tr>
		</table>
	</form>
</body>
</html>
